#include <stdio.h>  
#include <stdlib.h>  
  
// 定义链表节点结构体  
struct ListNode {  
    int val;  
    struct ListNode *next;  
};  
  
// 定义函数实现链表节点的创建  
struct ListNode* createNode(int val) {  
    struct ListNode *node = (struct ListNode*)malloc(sizeof(struct ListNode));  
    node->val = val;  
    node->next = NULL;  
    return node;  
}  
  
// 定义函数实现链表的划分  
struct ListNode* partition(struct ListNode* head, int k) {  
    struct ListNode *left = NULL, *right = NULL;  
    struct ListNode *curr = head;  
    while (curr != NULL) {  
        if (curr->val < k) {  
            if (left == NULL) {  
                left = curr;  
            } else {  
                left->next = curr;  
            }  
            left = left->next;  
        } else {  
            if (right == NULL) {  
                right = curr;  
            } else {  
                right->next = curr;  
            }  
            right = right->next;  
        }  
        curr = curr->next;  
    }  
    if (left != NULL) {  
        left->next = right;  
    }  
    return left;  
}  
  
// 定义函数实现链表的打印输出  
void printList(struct ListNode* head) {  
    struct ListNode *curr = head;  
    while (curr != NULL) {  
        printf("%d ", curr->val);  
        curr = curr->next;  
    }  
    printf("\n");  
}  
  
// 测试代码  
int main() {  
    struct ListNode *head = createNode(1);  
    head->next = createNode(4);  
    head->next->next = createNode(3);  
    head->next->next->next = createNode(2);  
    head->next->next->next->next = createNode(5);  
    head->next->next->next->next->next = createNode(2);  
    head->next->next->next->next->next->next = createNode(4);  
    head->next->next->next->next->next->next->next = createNode(6);  
    head->next->next->next->next->next->next->next->next = createNode(3);  
    int k = 3; // 以3为基准进行划分，将链表划分为小于3的部分和大于等于3的部分。